package com.springbootblog.config;

import com.springbootblog.filter.FontendsFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

/**
 * filter配置
 */
@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<FontendsFilter> registrationBean(){
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        /*将文本过滤器类注册到容器中*/
        filter.setEncoding("utf-8");
        filter.setForceEncoding(true);
        FilterRegistrationBean<FontendsFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new FontendsFilter());
        filterRegistrationBean.addUrlPatterns("/*");  //setUrlPatterns() 一次性将映射关系配置进去
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setName("filter");
        return filterRegistrationBean;
    }
}
